home *** CD-ROM | disk | FTP | other *** search
- Path: garden.csc.calpoly.edu!not-for-mail
- From: dstubbs@garden.csc.calpoly.edu (Dan Stubbs)
- Newsgroups: comp.lang.c
- Subject: Re: Beginer C please help me
- Date: 29 Mar 1996 08:32:40 -0800
- Organization: Cal Poly, San Luis Obispo
- Message-ID: <4jh3b8$e5q@garden.csc.calpoly.edu>
- References: <DoLCFx.B7x.0.bloor@torfree.net> <4iq6uc$evq@daryl.scsn.net> <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de> <4jeljl$8cg_001@nuts.nwu.edu>
- NNTP-Posting-User: dstubbs@garden.csc.calpoly.edu
-
- In article <4jeljl$8cg_001@nuts.nwu.edu>, Laurie Long <llong@nwu.edu> wrote:
- >In article <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de>,
- > schoof@informatik.uni-wuerzburg.de (Jochen Schoof) wrote:
- >>Scott Shrader (shrader@scsn.net) wrote:
- >>: In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net says...
- >>: >
- >>: >#include <stdio.h>
- >>: >#include <math.h>
- >>: >main ()
- >>: >{
- >>: >float n;
- >>: >n=(9/5);
- >>: >printf ("n= %1.3f\n", n);
- >>: >}
- >>: >I have complied and run the programme & I got the answer n=1.000
- >>: >--
- >>:What you are asking the program to do is convert an int value (9/5 = 1) to a
- > float. You need to type cast either the dividend or the divisor as a float.
- >
- I think the preferred solution is to use
-
- n = 9.0 / 5.0;
-
- Remember that 9 and 5 are integers but 9.0 and 5.0 are floating point types.
- Use the ones that are consistent with the rest of your expression.
-
- Also, you are not using math.h in this program so you can delete
- #include <math.h>
-
-
-